
var RootUrl = "";

function removePanel() {
    var tab = $('#tabs').tabs('getSelected');
    if (tab) {
        var index = $('#tabs').tabs('getTabIndex', tab);
        $('#tabs').tabs('close', index);
    }
}


function tabClose() {
    /*双击关闭TAB选项卡*/
    $(".tabs-inner").dblclick(function () {
        var subtitle = $(this).children(".tabs-closable").text();
        $('#tabs').tabs('close', subtitle);
    })
    /*为选项卡绑定右键*/
    $(".tabs-inner").bind('contextmenu', function (e) {
        $('#mm').menu('show', {
            left: e.pageX,
            top: e.pageY
        });

        var subtitle = $(this).children(".tabs-closable").text();

        $('#mm').data("currtab", subtitle);
        $('#tabs').tabs('select', subtitle);
        return false;
    });
} 
 

//绑定右键菜单事件
function tabCloseEven() {
    //刷新
    $('#mm-tabupdate').click(function () {
        var currTab = $('#tabs').tabs('getSelected');
        var url = $(currTab.panel('options').content).attr('src');
        if (url != undefined && currTab.panel('options').title != '首页') {
            $('#tabs').tabs('update', {
                tab: currTab,
                options: {
                    content: createFrame(url)
                }
            })
        }
    })
    //关闭当前
    $('#mm-tabclose').click(function () {
        var currtab_title = $('#mm').data("currtab");
        $('#tabs').tabs('close', currtab_title);
    })
    //全部关闭
    $('#mm-tabcloseall').click(function () {
        $('.tabs-inner span').each(function (i, n) {
            var t = $(n).text();
            if (t != '首页') {
                $('#tabs').tabs('close', t);
            }
        });
    });
    //关闭除当前之外的TAB
    $('#mm-tabcloseother').click(function () {
        var prevall = $('.tabs-selected').prevAll();
        var nextall = $('.tabs-selected').nextAll();
        if (prevall.length > 0) {
            prevall.each(function (i, n) {
                var t = $('a:eq(0) span', $(n)).text();
                if (t != '首页') {
                    $('#tabs').tabs('close', t);
                }
            });
        }
        if (nextall.length > 0) {
            nextall.each(function (i, n) {
                var t = $('a:eq(0) span', $(n)).text();
                if (t != '首页') {
                    $('#tabs').tabs('close', t);
                }
            });
        }
        return false;
    });
    //关闭当前右侧的TAB
    $('#mm-tabcloseright').click(function () {
        var nextall = $('.tabs-selected').nextAll();
        if (nextall.length == 0) {
            //msgShow('系统提示','后边没有啦~~','error');
            alert('后边没有啦~~');
            return false;
        }
        nextall.each(function (i, n) {
            var t = $('a:eq(0) span', $(n)).text();
            $('#tabs').tabs('close', t);
        });
        return false;
    });
    //关闭当前左侧的TAB
    $('#mm-tabcloseleft').click(function () {
        var prevall = $('.tabs-selected').prevAll();
        if (prevall.length == 0) {
            alert('到头了，前边没有啦~~');
            return false;
        }
        prevall.each(function (i, n) {
            var t = $('a:eq(0) span', $(n)).text();
            $('#tabs').tabs('close', t);
        });
        return false;
    });

    //退出
    $("#mm-exit").click(function () {
        $('#mm').menu('hide');
    })
}
 
 

function addPanel(id, title, src) {
    var panelHeight = $('#tabs').tabs('getTab', 0).height()-5; 
    $('#tabs').tabs('add', {
        iconCls: 'icon-' + id,
        title: title,
        content: '<iframe scrolling="yes" frameborder="0"  src="' + src + '" style="width:100%;height:' + panelHeight + 'px;"></iframe>',
        closable: true
    });
    tabClose();
}
   


function navonclick(info) {  
	    var id = info.id.trim();
	    var text = info.text.trim();
	    var url=Onluy.basePath()+'/sysmgr/appnews/index?roottypeid='+id;   
		addPanel(id,text ,url); 
}


function InitNav() { 
	 $('#nav').tree({   
	    	onClick: navonclick,
	    	method: 'get', 
	    	data:{roottypeid:$('#roottypeid').val()},
	    	url:Onluy.basePath()+'/sysmgr/type/simplenav',
	        loader:Onluy.easyui.treeLoader, 
	        loadFilter: function(data){ 
	        	var i=0;
	        	for(i=0;i<data.length;i++){ 
	        		var temp=data[i];
	        		data[i].id=temp['Type_ID']; 
	        		data[i].text=temp['Type_Name'] ;
	        		if(data[i].childcount>0){
	            		data[i].state="closed"  ; 
	        		}else{
	            		data[i].state="open"  ;
	        		} 
	        	} 
	        	//alert(JSON.stringify(data));
	            return data;   
	        }   
	    }); 
     
}
 


$(function () {
    tabCloseEven();
    InitNav(); //初始化菜单 
    $('#tabs').tabs({
        // tabPosition:'left' ,       
        border: false
    }); 
     
    $('#londing').window('close');
});
 